package com.gears_software.bbnetwork.activitys;

import java.util.List;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.annotations.sharedpreferences.Pref;

import android.app.Activity;
import android.view.Window;
import android.widget.ListView;

import com.avos.avoscloud.AVAnalytics;
import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.adapters.CardItemAdapter;
import com.gears_software.bbnetwork.datas.finders.IBBNetworkFinder;
import com.gears_software.bbnetwork.datas.finders.impl.IBBNetworkFinderImpl;
import com.gears_software.bbnetwork.datas.models.CurrentBankInfoModel;
import com.gears_software.bbnetwork.datas.models.ResultModel;
import com.gears_software.bbnetwork.datas.models.ReturnCode;
import com.gears_software.bbnetwork.utlis.BBNetworkSharedPref_;
import com.gears_software.bbnetwork.utlis.ToastUI;

/**
 * 绑定中的银行卡
 * @author DY-PC
 *
 */
@EActivity(R.layout.activity_mycard)
@WindowFeature(Window.FEATURE_NO_TITLE)
public class MyCardActivity extends Activity {
	
	CardItemAdapter adapter;
	
	@ViewById
	ListView list_card;
	
	@Bean(IBBNetworkFinderImpl.class)
	IBBNetworkFinder finder;
	
	List<CurrentBankInfoModel> list;
	
	@Bean
	ToastUI toast;
	
	@Pref
	BBNetworkSharedPref_ sp;
	
	@AfterViews
	void onCreate(){
		getInfo();
	}
	
	@Background
	void getInfo(){
		ResultModel<List<CurrentBankInfoModel>> res = finder.getCardInfo(sp.userId().get());
		if(res.getReturnCode().equals(ReturnCode.SUCCEED)){
			init(res.getResObj());
		}else{
			showTxt(res.getMessage());
		}
	}
	
	@UiThread
	void init(List<CurrentBankInfoModel> list){
		this.list = list;
		adapter = new CardItemAdapter(this.list, this,MyCardActivity.this);
		list_card.setAdapter(adapter);
	}
	
	@UiThread
	void showTxt(String txt){
		toast.ShowToast(txt);
	}
	
	//后退
	@Click
	void image_back(){
		finish();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		 AVAnalytics.onResume(this);
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AVAnalytics.onPause(this);
	}
	
}
